<?php
/**
 *
 * @author fanzhanao
 * @version 
 */
class cartoon_model_collect extends cartoon_model_bmodel {
	public function __construct(){
    	parent::__construct();
        $this->table = 'cartoon_collect';
    }
    /**
     * 添加收藏
     *
     * @param unknown_type $cartoon_id
     * @param unknown_type $uid
     */
    public function add($args,$cartoon_id,$uid,$chapter_id=0){
    	if(!($args['cartoon_id'] && $args['uid'] )) return false;
    	if($this->has($args['cartoon_id'],$args['uid'],$args['chapter_id'])) return ERR_EXISTS;
    	return $this->db->insert($this->table,$args);
    }
    
    /**
     * 取消收藏
     *
     * @param unknown_type $cartoon_id
     * @param unknown_type $uid
     */
    public function remove($id){
    	if(!($cartoon_id && $uid )) return false;
    	return $this->db->query("DELETE FROM $this->table WHERE id=$id ");
    }
    
    public function has($cartoon_id,$uid,$chapter_id){
    	$sql = "SELECT id FROM $this->table WHERE uid = $uid AND cartoon_id = $cartoon_id AND chapter_id = $chapter_id";
    	$rs = $this->db->fetchField($sql,'id');
    	return $rs?true:false;
    }
}